<%@page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp"  %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>User's prices</title>
    <c:url var="jquery_custom_css" value="/ui/jquery-ui-1.8.4.custom.css" />
    <link href="${jquery_custom_css}" rel="stylesheet" type="text/css" />
    <c:url var="jquery_treeview_css" value="/css/jquery.treeview.css" />
    <link href="${jquery_treeview_css}" rel="stylesheet" type="text/css" />
    <c:url var="housewifes_css" value="/css/housewifes.css" />
    <link href="${housewifes_css}" rel="stylesheet" type="text/css" />

    <c:url var="jquery_js" value="/script/jquery-1.4.2.js" />
    <script type="text/javascript" src="${jquery_js}"></script>
    <c:url var="jquery_cookie_js" value="/script/jquery.cookie.js" />
    <script type="text/javascript" src="${jquery_cookie_js}"></script>
    <c:url var="jquery_treeview_js" value="/script/jquery.treeview.js" />
    <script type="text/javascript" src="${jquery_treeview_js}"></script>
    <c:url var="jquery_custom_js" value="/script/jquery-ui-1.8.4.custom.min.js" />
    <script type="text/javascript" src="${jquery_custom_js}"></script>

    <c:url var="hw_js" value="/script/housewifes.js" />
    <script type="text/javascript" src="${hw_js}"></script>
</head>
<body>
<c:import url="../pagemenus/mainUserMenu.jsp"/>
<br/>
Here there are wares that are used in dish recipes that you created or used
<br/>

<c:if test="${user.region == null}">
    <spring:message code="user.prices.page.no.region.suggest"/>
</c:if>

<table border="1" >
    <tr>
        <th>ware</th>
        <th>common region price</th>
        <th>user's price</th>
    </tr>
    <c:forEach var="userWare" items="${usersWares}">
        <c:set var="ware" value="${userWare.ware}"/>
        <tr>
            <td>
                <span id="ware_name_${ware.id}"><c:out value="${ware.name}"/></span>
            </td>
            <td>
                <c:choose>
                    <c:when test="${userWare.wareRegionPrice != null}">
                        <c:out value="${userWare.wareRegionPrice.price}"/>
                    </c:when>
                    <c:otherwise>
                        <spring:message code="ware.region.price.not.found"/>
                    </c:otherwise>
                </c:choose>
            </td>

            <td>

                <c:choose>
                    <c:when test="${userWare.wareUserPrice != null}">
                        <span id="users_ware_price_${ware.id}"><c:out value="${userWare.wareUserPrice.price}"/></span>
                    </c:when>
                    <c:otherwise>
                        <span id="users_ware_price_${ware.id}"><spring:message code="ware.user.price.not.found"/></span>
                    </c:otherwise>
                </c:choose>
                <span class="dialog_link select_user_price"><span class="hidden_id">${ware.id}</span>set price</span>
            </td>
        </tr>
    </c:forEach>
</table>
<c:if test="${not empty pageNums}">
<table style="vertical-align:bottom;" border="1">
    <tr><td valign="bottom" align="center">

        <table>
            <tr>
                <c:forEach var="pageNum" items="${pageNums}">
                    <td>
                        <c:choose>
                            <c:when test="${pageNum >= 0 && pageNum != selectedPage}">
                        <span class="page_select_link"><span class="hidden_id">${pageNum}</span><b><c:out
                                value="${pageNum + 1}"/></b></span>
                            </c:when>
                            <c:when test="${pageNum >= 0 && pageNum == selectedPage}">
                                <c:out value="${pageNum + 1}"/>
                            </c:when>
                            <c:otherwise>...</c:otherwise>
                        </c:choose>
                    </td>
                </c:forEach>
            </tr>
        </table>

    </td></tr>
</table>
</c:if>

<c:import url="setUsersWarePriceDialogBlock.jsp"/>

<div id="loading_dialog" style="display:none;">
    <img src="img/loading.gif" style="text-align:center;" width="100%" height="100%" />
</div>

<script type="text/javascript">

    $(document).ready(function() {

        var priceDialog = new WareUserPriceSetDialog(
                "<c:url value="/set-users-ware-price.html"/>",
                "set_users_ware_price_form",
                "set_price_form_ware_id",
                "set_price_form_ware_name",
                "set_price_form_ware_price"
        );

        priceDialog.bindSubmitPriceAction(function(wareId, warePrice) {
            $("#users_ware_price_" + wareId).html(warePrice);
        });

        $(".select_user_price").each(function() {
            var wareId = $(this).children(".hidden_id").text();
            var wareName = $("#ware_name_" + wareId).text();
            var wareCurPrice = $("#users_ware_price_" + wareId).text();
            if (wareCurPrice == "<spring:message code="ware.user.price.not.found"/>") {
                wareCurPrice = 0;
            }
            $(this).click(function() {
                priceDialog.showDialogForm(wareId, wareName, function(){
                    var wareCurPrice = $("#users_ware_price_" + wareId).text();
                    if (wareCurPrice == "<spring:message code="ware.user.price.not.found"/>") {
                        wareCurPrice = 0;
                    }
                    return wareCurPrice;
                });
            });
        });

    });

</script>

</body>
</html>